﻿using EBA.Contracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EBA.Logging
{
    /// <summary>
    /// Logger utilities
    /// </summary>
    public static class LoggerEx
    {
        /// <summary>
        /// Log a trace message
        /// </summary>
        /// <typeparam name="TData">custom log data type</typeparam>
        /// <param name="logger">logger instance</param>
        /// <param name="sender">log sender</param>
        /// <param name="message">log message</param>
        /// <param name="data">custom log data</param>
        public static void Trace<TData>(this ILogger logger, string message, string name = null)
        {
            Contract.Requires<ArgumentNullException>(logger != null, "logger");

            logger.Log(message, LogLevel.Trace, name);
        }


        /// <summary>
        /// Log a trace message
        /// </summary>
        /// <typeparam name="TData">custom log data type</typeparam>
        /// <param name="logger">logger instance</param>
        /// <param name="sender">log sender</param>
        /// <param name="message">log message</param>
        /// <param name="data">custom log data</param>
        public static void Debug<TData>(this ILogger logger, string message, string name = null)
        {
            Contract.Requires<ArgumentNullException>(logger != null, "logger");

            logger.Log(message, LogLevel.Debug, name);
        }

        /// <summary>
        /// Log a info message
        /// </summary>
        /// <typeparam name="TData">custom log data type</typeparam>
        /// <param name="logger">logger instance</param>
        /// <param name="sender">log sender</param>
        /// <param name="message">log message</param>
        /// <param name="data">custom log data</param>
        public static void Info<TData>(this ILogger logger, string message, string name=null)
        {
            Contract.Requires<ArgumentNullException>(logger != null, "logger");

            logger.Log(message, LogLevel.Info , name);
        }

        /// <summary>
        /// Log a warn message
        /// </summary>
        /// <typeparam name="TData">custom log data type</typeparam>
        /// <param name="logger">logger instance</param>
        /// <param name="sender">log sender</param>
        /// <param name="message">log message</param>
        /// <param name="data">custom log data</param>
        public static void Warn<TData>(this ILogger logger, string message, string name=null)
        {
            Contract.Requires<ArgumentNullException>(logger != null, "logger");

            logger.Log(message, LogLevel.Warn, name);
        }

        /// <summary>
        /// Log a error message
        /// </summary>
        /// <typeparam name="TData">custom log data type</typeparam>
        /// <param name="logger">logger instance</param>
        /// <param name="sender">log sender</param>
        /// <param name="message">log message</param>
        /// <param name="data">custom log data</param>
        public static void Error<TData>(this ILogger logger, string message, string name = null)
        {
            Contract.Requires<ArgumentNullException>(logger != null, "logger");

            logger.Log(message, LogLevel.Error,name);
        }

        /// <summary>
        /// Log a fatal message
        /// </summary>
        /// <typeparam name="TData">custom log data type</typeparam>
        /// <param name="logger">logger instance</param>
        /// <param name="sender">log sender</param>
        /// <param name="message">log message</param>
        /// <param name="data">custom log data</param>
        public static void Fatal<TData>(this ILogger logger, string message, string name = null)
        {
            Contract.Requires<ArgumentNullException>(logger != null, "logger");

            logger.Log(message, LogLevel.Fatal, name);
        }

        /// <summary>
        /// Log a activty message
        /// </summary>
        /// <typeparam name="TData">custom log data type</typeparam>
        /// <param name="logger">logger instance</param>
        /// <param name="sender">log sender</param>
        /// <param name="message">log message</param>
        /// <param name="data">custom log data</param>
        public static void Activty<TData>(this ILogger logger, string message, string name = null)
        {
            Contract.Requires<ArgumentNullException>(logger != null, "logger");

            logger.Log(message, LogLevel.Activty, name);
        }
    }
}
